<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<style>
    div {
        width: 200px;
        height: 200px;
        background: #58a;
    }
</style>

<body>
    <div class="ad"></div>
    <script>
        //需求1 点击div 2s后颜色变为粉色
        let ad = document.querySelector('.ad');
        // ad.addEventListener('click', function() { 
        //     let _this = this;
        //     setInterval(function() {
        //         _this.style.background = 'pink';
        //     }, 2000);
        // });
        ad.addEventListener('click', function() {
            setInterval(() => {
                this.style.background = 'pink';
            }, 2000);
        });
        //需求2 从数组中返回偶数的元素
        const arr = [1, 6, 9, 10, 100, 255];
        // const result = arr.filter(function(item) {
        //     if (item % 2 === 0) {
        //         return true;
        //     } else {
        //         return false;
        //     }
        // })
        const result = arr.filter(item => item % 2 === 0)
        console.log(result);
    </script>
</body>

</html>